import {createAction, createThunkAction} from "../../lib/redux-utils";
import {get, postForm, postJson} from "../../lib/http";
import {getPrincipal} from "../../lib/identity";

const principal = getPrincipal();
const path = "/coach";
const ACTION_PREFIX = "COACH.";
export const query = createThunkAction(ACTION_PREFIX + "QUERY", () =>
    get(path + "/all")
);
export const select = createAction(ACTION_PREFIX + "SELECT");
export const showCreate = createAction(ACTION_PREFIX + "SHOW_CREATE");
export const hideCreate = createAction(ACTION_PREFIX + "HIDE_CREATE");

export const create = createThunkAction(ACTION_PREFIX + "CREATE", params =>
    postJson(path + "/create", params)
);
export const del = createThunkAction(ACTION_PREFIX + "DELETE", params =>
    get(path + "/delete/" + params + "/" + principal.id)
);
export const importGoods = createThunkAction(ACTION_PREFIX + "IMPORT", params =>
    postForm(path + "/import/" + params.opId, params)
);